package com.atguigu.day02;

public class Example3 {
    public static void main(String[] args) {
        System.out.println(fibIter(45));
        System.out.println(fib(45));
    }

    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return n;
        } else {
            return fib(n-1) + fib(n-2);
        }
    }

    public static int fibIter(int n) {
        if (n == 1 || n == 2) {
            return n;
        } else {
            int[] array = new int[n + 1];
            array[1] = 1;
            array[2] = 2;
            for (int i = 3; i < n + 1; i++) {
                array[i] = array[i - 1] + array[i - 2];
            }
            return array[n];
        }
    }
}
